<?php

namespace Modules\System\Services\Mds;

class MDSCurl
{

    /**
     * post带数据请求
     *
     */
    static public function post($url,$data){

        $ch = curl_init($url);
        curl_setopt($ch,CURLOPT_HEADER,0);
        curl_setopt($ch,CURLOPT_TIMEOUT,300);  //定义超时300秒钟
        $mes = curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); //终端不验证curl
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        $result = curl_exec($ch);
        curl_close ( $ch );
        return $result;

    }

    /**
     * get带头数据请求
     *
     */
    static public function getHeader($url,$arr_headerAll){

        $curl = curl_init();
        // 发送 HTTP 请求
        curl_setopt_array($curl,array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'GET',
            CURLOPT_HTTPHEADER => $arr_headerAll,
        ));
        $response = curl_exec($curl);
        if($response === false){
            echo "Error in cURL : " . curl_error($curl);
            exit;
        }
        curl_close($curl);
        return $response;

    }


}